<template>
	<!-- 推广人数 -->
	<view>
		<u-navbar title="推广人数" placeholder :autoBack="true" leftIconColor="#E6A5B4" bgColor="#FFFFFF"
			:titleStyle="titleStyle">

		</u-navbar>
		<u-sticky zIndex="99" :offsetTop="statusBarHeight+44" bgColor="#FFFFFF">
			<u-tabs :list="tabList" lineColor="#E6A5B4" :activeStyle="activeStyle" :inactiveStyle="inactiveStyle"
				@click="onSelectClick" />
		</u-sticky>

		<view v-if="mUserData.length>0">
			<scroll-view style="height: 100vh;" :scroll-y="true" @scroll="onScroll" :scroll-with-animation="true"
				:refresher-enabled="true" :refresher-triggered="triggered" @refresherrefresh="onDataList"
				refresher-default-style="white" @scrolltolower="scrolltolower">
				<view v-for="(item,key) in mUserData" :key="key" class="listBg">
					<view class="itemV">
						<image :src="item.avatar"></image>
						<view class="subV">
							<view class="nameTv">{{item.nickname}}</view>
							<view class="timeTv">{{item.createtime}}</view>
						</view>
						<view v-if="item" class="moneyTv">+{{item.rechage}}</view>
					</view>
					<view class="lineV"></view>
				</view>
			</scroll-view>
		</view>

		<view v-if="mUserData.length==0"
			style="justify-content: center; align-items: center; display: flex; height: 50vh; color: #8D8D8D;">
			暂无数据
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 20,
				titleStyle: {
					"color": "#ffffff"
				},
				activeStyle: {
					"color": "#E6A5B4D",
					"font-size": "32rpx"
				},
				inactiveStyle: {
					"color": "#8D8D8D",
					"font-size": "32rpx"
				},
				tabList: [{
					name: '全部' //
				}, {
					name: '已充值' //
				}, {
					name: '未充值' //
				}],
				mStatus: "",
				mUserData: [],
				mPage: 1,
				scrollTop: 0,
				triggered: false,
				mRoleId:''
			}
		},
		onLoad(e) {
			this.mRoleId = e.id;
			uni.getSystemInfo({
				success: res => {
					this.statusBarHeight = res.statusBarHeight
				}
			})
			this.getUsers();
		},
		methods: {
			onDataList() {
				if (this.scrollTop == 0) {
					this.triggered = true;
					this.mPage = 1
					this.getUsers()
				}
			},
			scrolltolower() { //上拉加载
				this.mPage++
				this.getUsers()
			},
			onScroll(e) {
				this.scrollTop = e.detail.scrollTop
			},
			onSelectClick(e) {
				let index = e.name;
				if (index == "全部") {
					this.mPage = 1;
					this.mStatus = "";
					this.getUsers();
				} else if (index == "已充值") {
					this.mPage = 1;
					this.mStatus = "1";
					this.getUsers();
				} else if (index == "未充值") {
					this.mPage = 1;
					this.mStatus = "0";
					this.getUsers();
				}
			},
			getUsers() {
				this.$api.getUsers({
					status: this.mStatus,
					page: this.mPage,
					role_id:this.mRoleId
				}).then((res) => {
					
					if (this.mPage == 1) {
						this.mUserData = res.rows;
					} else {
						this.mUserData.push(...res.rows)
					}
					this.triggered = false;
				}).catch((e) => {
					this.triggered = false;
					uni.$u.toast(e.msg === undefined ? "请求失败" : e.msg)
				})
			},
		}
	}
</script>

<style lang="scss">
	.listBg {
		display: flex;
		flex-direction: column;

		.itemV {
			height: 144rpx;
			padding-left: 30rpx;
			padding-right: 30rpx;
			display: flex;
			align-items: center;

			image {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}

			.subV {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding-left: 20rpx;

				.nameTv {
					color: #fff;
					font-size: 32rpx;
				}

				.timeTv {
					margin-top: 10rpx;
					font-size: 24rpx;
					color: #939393;
				}
			}

			.moneyTv {
				font-size: 32rpx;
				color: #fff;
			}
		}

		.lineV {
			width: 100%;
			height: 1rpx;
			background: #545454;
		}
	}
</style>
